package com.atguigu.o_homework_adc_123;

// 判断 干活 通知
class Printer{
    String s = null;

    public synchronized void printAbc(){
        while (s!=null&&s=="abc"){
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        s = "abc";
        System.out.println(Thread.currentThread().getName()+s);
        this.notifyAll();
    }

    public synchronized void print123() throws InterruptedException {
        while (s!=null&&s=="123"){
            this.wait();
        }
        s = "123";
        System.out.println(Thread.currentThread().getName()+s);
        this.notifyAll();
    }
}

public class Test {
    public static void main(String[] args) {
        Printer printer = new Printer();
        new Thread(()->{
            for (int i = 0; i < 10; i++) {
                printer.printAbc();
            }
        }, "t1").start();
        new Thread(()->{
            for (int i = 0; i < 10; i++) {
                try {
                    printer.print123();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "t2").start();
    }
}
